//
//  NetMusicViewController.m
//  DolphinMusic
//
//  Created by dllo on 15/3/21.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "NetMusicViewController.h"
#import "RecommendCollectionViewCell.h"
#import "HotSongTableViewCell.h"
#import "HotSong.h"
#import "Flag.h"


#import "AFHTTPRequestOperation.h"
#import "NetHandler.h"
#import "MBProgressHUD.h"

#import "SongList.h"
#import "ListCollectionViewCell.h"
#import "UIButton+ADDString.h"
#import "ButtonAndLabelView.h"

#import "ListViewController.h"
#import "NewSongViewController.h"

#import "Singer.h"
#import "HotSingerCollectionViewCell.h"
#import "SingerTypeTableViewCell.h"


#import "TypeSingerViewController.h"
#import "SIngerViewController.h"
#import "TopList.h"
#import "TopListTableViewCell.h"

#import "TopListViewController.h"

#import "SongListCollectionViewCell.h"
#import "MusicPlayViewController.h"
#import "PlayView.h"
#import "UIButton+WebCache.h"
#import "UIScrollView+MJRefresh.h"
#import "MJRefresh.h"

#import "MoreSingerViewController.h"

@interface NetMusicViewController () <UICollectionViewDataSource, UICollectionViewDelegate, UIScrollViewDelegate, UITableViewDataSource, UITableViewDelegate>

/************************* 推荐页面 **************************/

// 底层横向滑动的scrollView和每个页面上下滑动的scrollView
@property (nonatomic, retain)UIScrollView *bgScrollView;
@property (nonatomic, retain)UIScrollView *recommendSV;
@property (nonatomic, retain)UIScrollView *singerSV;
@property (nonatomic, retain)UIScrollView *toplistSV;
@property (nonatomic, retain)NSTimer *timer;
@property (nonatomic, assign)NSInteger flag;



// 三个按钮之下的滚动条
@property (nonatomic, retain)UIView *changeView;

// 推荐页面的滚动推荐的地址, 图片的地址
@property (nonatomic, retain)UICollectionView *recommendCollectionView;
@property (nonatomic, retain)NSArray *recommendArr;
@property (nonatomic, retain)NSMutableArray *imageArr;

// 热门歌曲推荐

@property (nonatomic, retain)UITableView *hotSongsTV;
@property (nonatomic, retain)NSMutableArray *hotSongsArr;

// 歌单推荐

@property (nonatomic, retain)UICollectionView *listCollectionVIew;
@property (nonatomic, retain)NSMutableArray *listArr;

// 最新歌曲

@property (nonatomic, retain)NSString *leftButtonListID;
@property (nonatomic, retain)NSString *middleButtonID;
@property (nonatomic, retain)NSString *rightButtonID;

// 第一页的转
@property (nonatomic, retain)MBProgressHUD *HUD1;


/************************* 歌手页面 **************************/

@property (nonatomic, retain)UICollectionView *singerCollectionView;
@property (nonatomic, retain)NSMutableArray *singerArr;
@property (nonatomic, retain)MBProgressHUD *HUB2;
@property (nonatomic, retain)UITableView *singerTableView;
@property (nonatomic, retain)NSArray *singerTypeArr;
@property (nonatomic, retain)NSMutableArray *addressArr;


/************************* 榜单页面 **************************/

@property (nonatomic, retain)MBProgressHUD *HUD3;
@property (nonatomic, retain)UITableView *topListTableView;
@property (nonatomic, retain)NSMutableArray *topListArr;

/****************** 歌单页面 *******************/

@property (nonatomic, retain)UIView *songListView;
@property (nonatomic, retain)MBProgressHUD *HUD4;
@property (nonatomic, retain)UICollectionView *songListCollectionView;
@property (nonatomic, retain)NSMutableArray *songListArr;


@property (nonatomic, retain)NSArray *areaArr;
@property (nonatomic, retain)NSArray *sexArr;
@property (nonatomic, retain)NSString *nextPageAddress;
@property (nonatomic, assign)NSInteger page;


@end

CGFloat aa = 220.0 / 667;

CGFloat bb = 70.0 / 667;

@implementation NetMusicViewController

- (void)dealloc
{
    [_timer release];
    [_songListArr release];
    [_songListCollectionView release];
    [_HUD4 release];
    [_songListView release];
    [_topListArr release];
    [_topListTableView release];
    [_HUD3 release];
    [_addressArr release];
    [_singerTypeArr release];
    [_singerTableView release];
    [_HUB2 release];
    [_singerArr release];
    [_singerCollectionView release];
    [_HUD1 release];
    [_rightButtonID release];
    [_middleButtonID release];
    [_leftButtonListID release];
    [_imageArr release];
    [_hotSongsArr release];
    [_hotSongsTV release];
    [_recommendCollectionView release];
    [_changeView release];
    [_recommendArr release];
    [_toplistSV release];
    [_singerSV release];
    [_recommendSV release];
    [_bgScrollView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.buttonView.frame = self.netButton.frame;
    [self.localButton addTarget:self action:@selector(localMusicButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.FMButton addTarget:self action:@selector(FMButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.searchButton addTarget:self action:@selector(searchButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.settingButton addTarget:self action:@selector(settingButtonAction:) forControlEvents:UIControlEventTouchUpInside];
/************************ 上面勿动 ************************/
    
    
    NSArray *buttonTitleArr = @[@"推荐", @"歌手", @"排行榜", @"歌单"];
    for (NSInteger i = 0; i < 4; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.frame = CGRectMake(VIEW_WIDTH / 4 * i, 64, VIEW_WIDTH / 4, 30);
        button.tintColor = [UIColor blackColor];
        button.backgroundColor = [UIColor whiteColor];
        [button setTitle:buttonTitleArr[i] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(topButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button];
    }
    self.changeView = [[UIView alloc] initWithFrame:CGRectMake(0, 94, VIEW_WIDTH / 4, 6)];
    self.changeView.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:self.changeView];
    [_changeView release];
    
/******************** 底层的左右滚动 ********************/
    self.bgScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 100, VIEW_WIDTH, VIEW_HEIGHT - 100 - bb* VIEW_HEIGHT)];
    self.bgScrollView.contentSize = CGSizeMake(VIEW_WIDTH * 4, 100);
    self.bgScrollView.pagingEnabled = YES;
    self.bgScrollView.delegate = self;
    self.bgScrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:self.bgScrollView];
    [_bgScrollView release];
    
    
    self.recommendArr = [NSArray array];
    self.hotSongsArr = [NSMutableArray array];
    
    UIWindow *window = [[[UIApplication sharedApplication] windows] firstObject];
    PlayView *playView = (PlayView*)[window viewWithTag:10001];
    playView.target = self.navigationController;
    
    
    
    [self putRecommendPage];
    [self getDataOfSingerPage];
    [self putTopListPage];
    [self putSongListPage];
    
    
    
}


#pragma mark 推荐页面的布局
- (void)putRecommendPage
{
    self.recommendSV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, self.bgScrollView.frame.size.height)];
    self.recommendSV.showsVerticalScrollIndicator = NO;
    [self.bgScrollView addSubview:self.recommendSV];
    self.recommendSV.bounces = NO;
    [_recommendSV release];
    
    self.HUD1 = [[MBProgressHUD alloc] initWithView:self.recommendSV];
    [self.recommendSV addSubview:self.HUD1];
    self.HUD1.labelText = @"Music is on the way...";
    self.HUD1.dimBackground = YES;
    [self.HUD1 show:YES];
    [self setScrollRecommend];
}


/***************** 滚动推荐 *******************/
- (void)setScrollRecommend
{
    
    self.recommendArr = @[@"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.diy.getSongFromOfficalList&format=json&ver=2&code=mygsdaqg", @"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.diy.getSongFromOfficalList&format=json&ver=2&code=redvelvet1", @"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.diy.gedanInfo&format=json&listid=5228", @"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.diy.getSongFromOfficalList&format=json&ver=2&code=qckxq", @"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.album.getAlbumInfo&format=json&album_id=238752475", @"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.diy.getSongFromOfficalList&format=json&ver=2&code=mygsdaqg", @"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.diy.getSongFromOfficalList&format=json&ver=2&code=redvelvet1"];

    self.imageArr = [[NSMutableArray alloc] initWithObjects:@"http://b.hiphotos.baidu.com/ting/pic/item/5ab5c9ea15ce36d3538879713ef33a87e850b1e7.jpg", @"http://c.hiphotos.baidu.com/ting/pic/item/f9198618367adab43a4cb4038fd4b31c8601e4d6.jpg", @"http://c.hiphotos.baidu.com/ting/pic/item/b219ebc4b74543a9dee451961a178a82b80114e8.jpg", @"http://a.hiphotos.baidu.com/ting/pic/item/0bd162d9f2d3572c738368818e13632762d0c30e.jpg", @"http://musicdata.baidu.com/data2/pic/238754832/238754832.jpg", @"http://b.hiphotos.baidu.com/ting/pic/item/5ab5c9ea15ce36d3538879713ef33a87e850b1e7.jpg", @"http://c.hiphotos.baidu.com/ting/pic/item/f9198618367adab43a4cb4038fd4b31c8601e4d6.jpg", nil];
    
    [NetHandler getDataWithUrl:self.recommendArr[0] completion:^(id dict) {
        
        [self.HUD1 hide:YES];
        
            UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
            flowLayout.itemSize = CGSizeMake(VIEW_WIDTH, VIEW_HEIGHT * aa);
            flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
            flowLayout.minimumInteritemSpacing = 0;
            flowLayout.minimumLineSpacing = 0;
            flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        
            self.recommendCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT * aa) collectionViewLayout:flowLayout];
        self.recommendCollectionView.backgroundColor = [UIColor whiteColor];
            self.recommendCollectionView.dataSource = self;
            self.recommendCollectionView.delegate = self;
            self.recommendCollectionView.pagingEnabled = YES;
            self.recommendCollectionView.showsHorizontalScrollIndicator = NO;
        
        
        
            [self.recommendCollectionView registerClass:[RecommendCollectionViewCell class] forCellWithReuseIdentifier:@"recommendCollectionReuse"];
            [self.recommendSV addSubview:self.recommendCollectionView];
            [self.recommendCollectionView release];
        
        [self showHotSong];
    }];
    }



/***************** 热门歌曲推荐 *******************/

- (void)showHotSong
{
    NSString *str=[NSString stringWithFormat:@"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.song.getEditorRecommend&format=json&num=6"];
    NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        [self.HUD1 hide:YES];
        
        NSString *html = operation.responseString;
        NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];
        id dict=[NSJSONSerialization  JSONObjectWithData:data options:0 error:nil];
        NSArray *arr1 = [dict objectForKey:@"content"];
        NSArray *arr2 = [[arr1 firstObject] objectForKey:@"song_list"];
        for (NSDictionary *dic in arr2) {
            HotSong *hotSong = [[HotSong alloc] initWithDictionary:dic];
            [self.hotSongsArr addObject:hotSong];
            [hotSong release];
        }
        [self setHotSongTableView];
    }failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"发生错误！%@",error);
    }];
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [queue addOperation:operation];
}

- (void)setHotSongTableView
{
    UIView *coverView = [[UIView alloc] initWithFrame:CGRectMake(0, self.recommendCollectionView.frame.size.height, VIEW_WIDTH, 40)];
    coverView.backgroundColor = [UIColor whiteColor];
    [self.recommendSV addSubview:coverView];
    [coverView release];
    
    UIView *view11 = [[UIView alloc] initWithFrame:CGRectMake(10, self.recommendCollectionView.frame.size.height + 10, 5, 20)];
    view11.backgroundColor = [UIColor lightGrayColor];
    [self.recommendSV addSubview:view11];
    [view11 release];
    
    UILabel *label11 = [[UILabel alloc] initWithFrame:CGRectMake(20, self.recommendCollectionView.frame.size.height + 10, 200, 20)];
    label11.text = @"热门歌曲推荐";
    label11.font = [UIFont systemFontOfSize:18];
    [self.recommendSV addSubview:label11];
    [label11 release];
    
    UILabel *label12 = [[UILabel alloc] initWithFrame:CGRectMake(VIEW_WIDTH - 100, self.recommendCollectionView.frame.size.height + 10 + 5, 90, 15)];
    label12.text = @"每天更新";
    label12.alpha = 0.6;
    label12.textAlignment = NSTextAlignmentRight;
    label12.font = [UIFont systemFontOfSize:15];
    [self.recommendSV addSubview:label12];
    [label12 release];
    
    
    self.hotSongsTV = [[UITableView alloc] initWithFrame:CGRectMake(7.5, self.recommendCollectionView.frame.size.height + 40, VIEW_WIDTH - 15, 480) style:UITableViewStylePlain];
    self.hotSongsTV.backgroundColor = [UIColor whiteColor];
    self.hotSongsTV.rowHeight = 80;
    self.hotSongsTV.delegate = self;
    self.hotSongsTV.dataSource = self;
    self.hotSongsTV.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    [self.hotSongsTV registerClass:[HotSongTableViewCell class] forCellReuseIdentifier:@"hotsongReuse"];
    [self.recommendSV addSubview:self.hotSongsTV];
    [_hotSongsTV release];
    
 //   [self.HUD1 hide:YES];
    
    self.timer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
    [self.timer fire];
    
    [self showSonglist];
    
    
    
}

- (void)timerAction
{
    self.flag = self.flag % 7;
    
        self.recommendCollectionView.contentOffset = CGPointMake(self.flag * VIEW_WIDTH, 0);
    
    self.flag++;
}


// 开始滚动的时候让计时器停止

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    
    if (scrollView == self.recommendCollectionView) {
        [self.timer setFireDate:[NSDate distantFuture]];
    }
}


/***************** 歌单推荐 *******************/

- (void)showSonglist
{
    self.listArr = [NSMutableArray array];
    NSString *str=[NSString stringWithFormat:@"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.diy.getHotGeDanAndOfficial&format=json&num=6"];
    NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSString *html = operation.responseString;
        NSData* data=[html dataUsingEncoding:NSUTF8StringEncoding];
        id dict=[NSJSONSerialization  JSONObjectWithData:data options:0 error:nil];
        NSArray *arr = [[dict objectForKey:@"content"] objectForKey:@"list"];
        for (NSDictionary *dic in arr) {
            SongList *list = [[SongList alloc] initWithDictionary:dic];
            [self.listArr addObject:list];
            [list release];
        }
    
        [self setListCollectionView];
    }failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"发生错误！%@",error);
    }];
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [queue addOperation:operation];

    
}

- (void)setListCollectionView
{
    
    UIView *view21 = [[UIView alloc] initWithFrame:CGRectMake(10, self.hotSongsTV.frame.origin.y + self.hotSongsTV.frame.size.height + 10, 5, 20)];
    view21.backgroundColor = [UIColor lightGrayColor];
    [self.recommendSV addSubview:view21];
    [view21 release];
    
    UILabel *label21 = [[UILabel alloc] initWithFrame:CGRectMake(20, view21.frame.origin.y, 200, 20)];
    label21.text = @"歌单推荐";
    label21.font = [UIFont systemFontOfSize:17];
    [self.recommendSV addSubview:label21];
    [label21 release];
    
    UIButton *button22 = [UIButton buttonWithType:UIButtonTypeSystem];
    button22.frame = CGRectMake(VIEW_WIDTH - 50, view21.frame.origin.y + 5, 40, 15);
    [button22 setTitle:@"更多>" forState:UIControlStateNormal];
    button22.alpha = 0.6;
    button22.tintColor = [UIColor blackColor];
    button22.titleLabel.font = [UIFont systemFontOfSize:15];
    [button22 addTarget:self action:@selector(button22Action:) forControlEvents:UIControlEventTouchUpInside];
    [self.recommendSV addSubview:button22];

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake((VIEW_WIDTH - 33) / 3, 120);
    flowLayout.minimumInteritemSpacing = 8;
    flowLayout.minimumLineSpacing = 8;
    flowLayout.sectionInset = UIEdgeInsetsMake(8, 8, 8, 8);
    
    self.listCollectionVIew = [[UICollectionView alloc] initWithFrame:CGRectMake(0, view21.frame.origin.y + 20, VIEW_WIDTH, 267) collectionViewLayout:flowLayout];
    self.listCollectionVIew.backgroundColor = [UIColor whiteColor];
    self.listCollectionVIew.dataSource = self;
    self.listCollectionVIew.delegate = self;
    [self.listCollectionVIew registerClass:[ListCollectionViewCell class] forCellWithReuseIdentifier:@"listCollectionReuse"];
    [self.recommendSV addSubview:self.listCollectionVIew];
    [_listCollectionVIew release];
    
    
    [self showNewestSongLeft];
    [self showNewestSongRight];
    
    
    
}

- (void)button22Action:(UIButton *)button
{
    self.bgScrollView.contentOffset = CGPointMake(VIEW_WIDTH * 3, 0);
    self.changeView.frame = CGRectMake(3 * VIEW_WIDTH / 4, 94, VIEW_WIDTH / 4, 6);
}

/*********************** 最新歌曲 *********************/

- (void)showNewestSongLeft
{
    UIView *view31 = [[UIView alloc] initWithFrame:CGRectMake(10, self.listCollectionVIew.frame.origin.y + self.listCollectionVIew.frame.size.height + 10, 5, 20)];
    view31.backgroundColor = [UIColor lightGrayColor];
    [self.recommendSV addSubview:view31];
    [view31 release];
    
    UILabel *label31 = [[UILabel alloc] initWithFrame:CGRectMake(20, view31.frame.origin.y, 200, 20)];
    label31.text = @"最新歌曲";
    label31.font = [UIFont systemFontOfSize:17];
    [self.recommendSV addSubview:label31];
    [label31 release];
    
    UIButton *button32 = [UIButton buttonWithType:UIButtonTypeSystem];
    button32.frame = CGRectMake(VIEW_WIDTH - 50, view31.frame.origin.y + 5, 40, 15);
    [button32 setTitle:@"更多>" forState:UIControlStateNormal];
    button32.alpha = 0.6;
    button32.tintColor = [UIColor blackColor];
    [button32 addTarget:self action:@selector(button32Action:) forControlEvents:UIControlEventTouchUpInside];
    button32.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.recommendSV addSubview:button32];

    
    NSString *str = @"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.diy.getFirstPublish&format=json";
    [NetHandler getDataWithUrl:str completion:^(id dict) {
        
        NSDictionary *dic = [dict objectForKey:@"collection"];
        ButtonAndLabelView *left = [[ButtonAndLabelView alloc] initWithFrame:CGRectMake(10, view31.frame.origin.y + 30, (VIEW_WIDTH - 40) / 3, 157)];
        
        [left.imageView setImageWithURL:[NSURL URLWithString:[[dic objectForKey:@"pic"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
        
        [left.button addTarget:self action:@selector(leftButtonAction) forControlEvents:UIControlEventTouchUpInside];
        self.leftButtonListID = [dic objectForKey:@"list_id"];
        left.titleLabel.text = [dic objectForKey:@"title"];
        left.titleLabel.font = [UIFont systemFontOfSize:14];
        left.autorLabel.text = [dic objectForKey:@"message"];
        left.autorLabel.font = [UIFont systemFontOfSize:12];
        left.autorLabel.numberOfLines = 0;
        [left.autorLabel sizeToFit];
        [self.recommendSV addSubview:left];
        
        
       
        
    }];
}

- (void)button32Action:(UIButton *)button
{
    NewSongViewController *newSongVC = [[NewSongViewController alloc] init];
    newSongVC.addressStr = @"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.plaza.getRecommendAlbum&format=json&offset=0&limit=50";
    [self.navigationController pushViewController:newSongVC animated:YES];
    [newSongVC release];
}

- (void)leftButtonAction
{
    ListViewController *listVC = [[ListViewController alloc] init];
    [self.navigationController pushViewController:listVC animated:YES];
    listVC.addressStr = [NSString stringWithFormat:@"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.diy.gedanInfo&format=json&listid=%@", self.leftButtonListID];
    [listVC release];
}

- (void)middleButtonAction
{
    ListViewController *listVC = [[ListViewController alloc] init];
    [self.navigationController pushViewController:listVC animated:YES];
    listVC.addressStr = [NSString stringWithFormat:@"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.album.getAlbumInfo&format=json&album_id=%@", self.middleButtonID];
    [listVC release];

}

- (void)rightButtonAction
{
    ListViewController *listVC = [[ListViewController alloc] init];
    [self.navigationController pushViewController:listVC animated:YES];
    listVC.addressStr = [NSString stringWithFormat:@"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.album.getAlbumInfo&format=json&album_id=%@", self.rightButtonID];
    [listVC release];
}

- (void)showNewestSongRight
{
    NSString *str = @"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.plaza.getRecommendAlbum&format=json&offset=0&limit=2";
    [NetHandler getDataWithUrl:str completion:^(id dict) {
        
        NSArray *arr = [[[[dict objectForKey:@"plaze_album_list"] objectForKey:@"RM"] objectForKey:@"album_list"] objectForKey:@"list"];
        NSDictionary *dic1 = arr[0];
        NSDictionary *dic2 = arr[1];
        
        ButtonAndLabelView *right1 = [[ButtonAndLabelView alloc] initWithFrame:CGRectMake((VIEW_WIDTH - 40) / 3 + 20, self.listCollectionVIew.frame.origin.y + self.listCollectionVIew.frame.size.height + 40, (VIEW_WIDTH - 40) / 3, 157)];
        
        [right1.imageView setImageWithURL:[NSURL URLWithString:[[dic1 objectForKey:@"pic_radio"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
        
        [right1.button addTarget:self action:@selector(middleButtonAction) forControlEvents:UIControlEventTouchUpInside];
        right1.titleLabel.text = [dic1 objectForKey:@"title"];
        right1.titleLabel.font = [UIFont systemFontOfSize:14];
        right1.autorLabel.text = [dic1 objectForKey:@"author"];
        right1.autorLabel.font = [UIFont systemFontOfSize:12];
        right1.autorLabel.numberOfLines = 0;
        [right1.autorLabel sizeToFit];
        [self.recommendSV addSubview:right1];
        
        self.middleButtonID = [dic1 objectForKey:@"album_id"];
        
        ButtonAndLabelView *right2 = [[ButtonAndLabelView alloc] initWithFrame:CGRectMake((VIEW_WIDTH - 40) * 2 / 3 + 30, right1.frame.origin.y, (VIEW_WIDTH - 40) / 3, 157)];
        
        [right2.imageView setImageWithURL:[NSURL URLWithString:[[dic2 objectForKey:@"pic_radio"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
        
        [right2.button addTarget:self action:@selector(rightButtonAction) forControlEvents:UIControlEventTouchUpInside];
        right2.titleLabel.text = [dic2 objectForKey:@"title"];
        right2.titleLabel.font = [UIFont systemFontOfSize:14];
        right2.autorLabel.text = [dic2 objectForKey:@"author"];
        right2.autorLabel.font = [UIFont systemFontOfSize:12];
        right2.autorLabel.numberOfLines = 0;
        [right2.autorLabel sizeToFit];
        [self.recommendSV addSubview:right2];
        
        self.rightButtonID = [dic2 objectForKey:@"album_id"];
        
        CGFloat heightMax = right1.frame.size.height > right2.frame.size.height ? right1.frame.size.height : right2.frame.size.height;
        self.recommendSV.contentSize = CGSizeMake(0, right1.frame.origin.y + heightMax);
    }];
    
    
}





#pragma mark 歌手页面的布局

- (void)getDataOfSingerPage
{
    self.singerSV = [[UIScrollView alloc] initWithFrame:CGRectMake(VIEW_WIDTH, 0, VIEW_WIDTH, VIEW_HEIGHT - 100 - bb * VIEW_HEIGHT)];

    self.singerSV.backgroundColor = [UIColor whiteColor];
    self.singerSV.showsVerticalScrollIndicator = NO;
    [self.bgScrollView addSubview:self.singerSV];
    [_singerSV release];

    self.HUB2 = [[MBProgressHUD alloc] initWithView:self.singerSV];
    [self.singerSV addSubview:self.HUB2];
    self.HUB2.labelText = @"Music is on the way...";
    self.HUB2.dimBackground = YES;
    [self.HUB2 show:YES];
    
    
    self.singerArr = [NSMutableArray array];
    NSString *str = @"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.artist.getList&format=json&offset=0&limit=48&order=1&area=0&sex=0";
    [NetHandler getDataWithUrl:str completion:^(id dict) {
        NSArray *arr = [dict objectForKey:@"artist"];
//        for (NSDictionary *dic in arr) {
//            Singer *singer = [[Singer alloc] initWithDictionary:dic];
//            [self.singerArr addObject:singer];
//            [singer release];
//        }
        
        for (NSInteger i = 0; i < 12; i++) {
            NSDictionary *dic = arr[i];
            Singer *singer = [[Singer alloc] initWithDictionary:dic];
            [self.singerArr addObject:singer];
            [singer release];
        }
        
        [self putSingerPage];
    }];
    
    
}


- (void)putSingerPage
{
    
    
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(10, 20, 5, 22)];
    view2.backgroundColor = [UIColor lightGrayColor];
    [self.singerSV addSubview:view2];
    [view2 release];
    
    UILabel *hotSingerLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 150, 22)];
    hotSingerLabel.text = @"热门歌手";
    hotSingerLabel.font = [UIFont systemFontOfSize:17];
    [self.singerSV addSubview:hotSingerLabel];
    [hotSingerLabel release];
    
    UIButton *singerMoreButton = [UIButton buttonWithType:UIButtonTypeSystem];
    singerMoreButton.frame = CGRectMake(VIEW_WIDTH - 50, 10, 50, 40);
    [singerMoreButton setTitle:@"更多>" forState:UIControlStateNormal];
    [singerMoreButton addTarget:self action:@selector(singerMoreButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    singerMoreButton.tintColor = [UIColor lightGrayColor];
    [self.singerSV addSubview:singerMoreButton];
    
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake((VIEW_WIDTH - 33) / 3, (VIEW_WIDTH - 33) / 3 + 30);
    flowLayout.minimumInteritemSpacing = 11;
    flowLayout.minimumLineSpacing = 11;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.sectionInset = UIEdgeInsetsMake(8, 5.5, 0, 5.5);

    
    self.singerCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 45, VIEW_WIDTH, (VIEW_WIDTH - 33) / 3 + 30) collectionViewLayout:flowLayout];
    self.singerCollectionView.backgroundColor = [UIColor whiteColor];
    self.singerCollectionView.showsHorizontalScrollIndicator = NO;
    self.singerCollectionView.delegate = self;
    self.singerCollectionView.dataSource = self;
    self.singerCollectionView.pagingEnabled = YES;
    [self.singerCollectionView registerClass:[HotSingerCollectionViewCell class] forCellWithReuseIdentifier:@"hotSingerReuse"];
    [self.singerSV addSubview:self.singerCollectionView];
    [_singerCollectionView release];
    
    
    
    self.singerTypeArr = @[@"华语男歌手", @"华语女歌手", @"华语组合", @"欧美男歌手", @"欧美女歌手", @"欧美组合", @"韩国男歌手", @"韩国女歌手", @"韩国组合", @"日本男歌手", @"日本女歌手", @"日本组合", @"其他歌手"];
    self.addressArr = [NSMutableArray array];
    self.singerTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 45 + (VIEW_WIDTH - 33) / 3 + 30 + 10, VIEW_WIDTH - 10, 70 *self.singerTypeArr.count) style:UITableViewStylePlain];
    self.singerTableView.dataSource = self;
    self.singerTableView.delegate = self;
    self.singerTableView.rowHeight = 70;
    [self.singerTableView registerClass:[SingerTypeTableViewCell class] forCellReuseIdentifier:@"singerTypeReuse"];
    [self.singerSV addSubview:self.singerTableView];
    [_singerTableView release];
    
    
    self.areaArr = @[@"6", @"6", @"6", @"3", @"3", @"3", @"7", @"7", @"7", @"60", @"60", @"60", @"5"];
    self.sexArr = @[@"1", @"2", @"3", @"1", @"2", @"3", @"1", @"2", @"3", @"1", @"2", @"3", @"0"];
    
    for (NSInteger i = 0; i < 13; i++) {
        NSString *str = [NSString stringWithFormat:@"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.artist.getList&format=json&offset=0&limit=48&order=1&area=%@&sex=%@", self.areaArr[i], self.sexArr[i]];
        [self.addressArr addObject:str];
    }
    
    [self.HUB2 hide:YES];
    
    self.singerSV.contentSize = CGSizeMake(0, self.singerTableView.frame.origin.y + self.singerTableView.frame.size.height);
}

- (void)singerMoreButtonAction:(UIButton *)button
{
    MoreSingerViewController *moreSingerVC = [[MoreSingerViewController alloc] init];
    [self.navigationController pushViewController:moreSingerVC animated:YES];
}


#pragma mark 榜单页面的布局

- (void)putTopListPage
{
    self.toplistSV = [[UIScrollView alloc] initWithFrame:CGRectMake(VIEW_WIDTH * 2, 0, VIEW_WIDTH, VIEW_HEIGHT - 100 - bb * VIEW_HEIGHT)];
    self.toplistSV.backgroundColor = [UIColor whiteColor];
    [self.bgScrollView addSubview:self.toplistSV];
    self.toplistSV.showsVerticalScrollIndicator = NO;
    [_toplistSV release];
    
    self.HUD3 = [[MBProgressHUD alloc] initWithView:self.toplistSV];
    [self.toplistSV addSubview:self.HUD3];
    self.HUD3.labelText = @"Music is on the way...";
    self.HUD3.dimBackground = YES;
    [self.HUD3 show:YES];
    
    NSString *addressStr = @"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.billboard.billCategory&format=json&from=ios&version=5.2.1&from=ios&channel=appstore";
    self.topListArr = [NSMutableArray array];
    [NetHandler getDataWithUrl:addressStr completion:^(id dict) {
        
        NSArray *arr = [dict objectForKey:@"content"];
        for (NSDictionary *dic in arr) {
            TopList *topList = [[TopList alloc] initWithDictionary:dic];
            [self.topListArr addObject:topList];
            [topList release];
        }
        
        
        self.topListTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, self.topListArr.count * 140) style:UITableViewStylePlain];
        self.topListTableView.rowHeight = 140;
        self.topListTableView.delegate = self;
        self.topListTableView.dataSource = self;
        [self.topListTableView registerClass:[TopListTableViewCell class] forCellReuseIdentifier:@"topListTableViewCellReuse"];
        
        [self.toplistSV addSubview:self.topListTableView];
        [_topListTableView release];
        
        self.toplistSV.contentSize = CGSizeMake(0, 140 * self.topListArr.count);
        
        [self.HUD3 hide:YES];
    }];
    
}

#pragma mark 歌单页面的布局

- (void)putSongListPage
{
    self.songListView = [[UIView alloc] initWithFrame:CGRectMake(VIEW_WIDTH * 3, 0, VIEW_WIDTH, VIEW_HEIGHT - 100 - bb * VIEW_HEIGHT)];
    self.songListView.backgroundColor = [UIColor yellowColor];
    [self.bgScrollView addSubview:self.songListView];
    [_songListView release];
    
    self.HUD4 = [[MBProgressHUD alloc] initWithView:self.songListView];
    [self.songListView addSubview:self.HUD4];
    self.HUD4.labelText = @"Music is on the way...";
    self.HUD4.dimBackground = YES;
    [self.HUD4 show:YES];
    
    
    NSString *address = @"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.diy.gedan&page_size=30&page_no=1";
    
    [NetHandler getDataWithUrl:address completion:^(id dict) {
        
        self.songListArr = [NSMutableArray array];
        
        NSArray *arr = [dict objectForKey:@"content"];
        for (NSDictionary *dic in arr) {
            SongList *list = [[SongList alloc] initWithDictionary:dic];
            [self.songListArr addObject:list];
            [list release];
        }
        
        
        UICollectionViewFlowLayout *flowLaout = [[UICollectionViewFlowLayout alloc] init];
        flowLaout.itemSize = CGSizeMake((VIEW_WIDTH - 30) / 2, (VIEW_WIDTH - 10) / 2 + 40);
        flowLaout.minimumInteritemSpacing = 10;
        flowLaout.minimumLineSpacing = 10;
        flowLaout.scrollDirection = UICollectionViewScrollDirectionVertical;
        flowLaout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
        
        self.songListCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT - 100 - bb * VIEW_HEIGHT) collectionViewLayout:flowLaout];
        self.songListCollectionView.delegate = self;
        self.songListCollectionView.dataSource = self;
        self.songListCollectionView.backgroundColor = [UIColor whiteColor];
        [self.songListCollectionView registerClass:[SongListCollectionViewCell class] forCellWithReuseIdentifier:@"songListCollectionReuse"];
        self.songListCollectionView.showsVerticalScrollIndicator = NO;
        [self.songListView addSubview:self.songListCollectionView];
        [_songListCollectionView release];
        
        self.page = 1;
        [self.songListCollectionView addLegendFooterWithRefreshingTarget:self refreshingAction:@selector(pullAction)];
        
        [self.HUD4 hide:YES];
        
    }];
    
}

- (void)pullAction
{
    self.page++;
    self.nextPageAddress = [NSString stringWithFormat:@"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.diy.gedan&page_size=30&page_no=%ld", self.page];
    [NetHandler getDataWithUrl:self.nextPageAddress completion:^(id dict) {
       
        NSArray *arr = [dict objectForKey:@"content"];
        
        if (arr != nil) {
            
        for (NSDictionary *dic in arr) {
            SongList *list = [[SongList alloc] initWithDictionary:dic];
            [self.songListArr addObject:list];
            [list release];
        }
            [self.songListCollectionView reloadData];
            [self.songListCollectionView.footer endRefreshing];
        }
        else {
            self.songListCollectionView.footer.state = MJRefreshFooterStateNoMoreData;
        }
        
    }];
    
    
}

#pragma mark 公用方法

// collectionView 相关方法

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (collectionView == self.recommendCollectionView) {
        return self.recommendArr.count;
    }
    if (collectionView == self.listCollectionVIew) {
        return self.listArr.count;
    }
    if (collectionView == self.singerCollectionView) {
        return self.singerArr.count;
    }
    
    if (collectionView == self.songListCollectionView) {
        return self.songListArr.count;
    }
    
    return 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (collectionView == self.recommendCollectionView) {
    RecommendCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recommendCollectionReuse" forIndexPath:indexPath];
    cell.nextPageStr = [self.recommendArr objectAtIndex:indexPath.row];
    cell.imageStr = [self.imageArr objectAtIndex:indexPath.row];
        
    return cell;
    }
    
    if (collectionView == self.listCollectionVIew) {
        ListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"listCollectionReuse" forIndexPath:indexPath];
        cell.list = [self.listArr objectAtIndex:indexPath.row];
        return cell;
    }
    
    if (collectionView == self.singerCollectionView) {
        HotSingerCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"hotSingerReuse" forIndexPath:indexPath];
        cell.singer = [self.singerArr objectAtIndex:indexPath.row];
        return cell;
    }
    
    if (collectionView == self.songListCollectionView) {
        SongListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"songListCollectionReuse" forIndexPath:indexPath];
        cell.list = [self.songListArr objectAtIndex:indexPath.row];
        return cell;
    }
    
    return nil;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    
    
    if (collectionView == self.recommendCollectionView) {
        ListViewController *listVC = [[ListViewController alloc] init];
        [self.navigationController pushViewController:listVC animated:YES];
    listVC.addressStr = [self.recommendArr objectAtIndex:indexPath.row];
        [listVC release];
    }
    if (collectionView == self.listCollectionVIew) {
        ListViewController *listVC = [[ListViewController alloc] init];
        [self.navigationController pushViewController:listVC animated:YES];
        SongList *list = [self.listArr objectAtIndex:indexPath.row];
        listVC.addressStr = [NSString stringWithFormat:@"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.diy.gedanInfo&format=json&listid=%@", list.listid];
        [listVC release];
    }
    
    if (collectionView == self.singerCollectionView) {
        SIngerViewController *singerVC = [[SIngerViewController alloc] init];
        singerVC.singer = [self.singerArr objectAtIndex:indexPath.row];
        [self.navigationController pushViewController:singerVC animated:YES];
        [singerVC release];
    }
    
    if (collectionView == self.songListCollectionView) {
        ListViewController *listVC = [[ListViewController alloc] init];
        
        SongList *list = [self.songListArr objectAtIndex:indexPath.row];
        listVC.addressStr = [NSString stringWithFormat:@"http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.0.1&method=baidu.ting.diy.gedanInfo&format=json&listid=%@", list.listid];
        
        [self.navigationController pushViewController:listVC animated:YES];
        [listVC release];
    }
    
    
}




- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    // 如果滚动的是推荐页面的滚动栏
    if (scrollView == self.recommendCollectionView) {
        if (scrollView.contentOffset.x == VIEW_WIDTH * 6) {
            scrollView.contentOffset = CGPointMake(VIEW_WIDTH, 0);
        }
        if (scrollView.contentOffset.x == 0) {
            scrollView.contentOffset = CGPointMake(VIEW_WIDTH * 5, 0);
        }
        
        self.flag = self.recommendCollectionView.contentOffset.x / VIEW_WIDTH;
        
        [self.timer setFireDate:[NSDate date]];
    }
    // 如果滚动的的是下层的大scrollView
    if (scrollView == self.bgScrollView) {
        self.changeView.frame = CGRectMake(self.bgScrollView.contentOffset.x / VIEW_WIDTH * VIEW_WIDTH / 4, 94, VIEW_WIDTH / 4, 6);
    }
    
    
}

// tableView 相关方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.hotSongsTV) {
        return self.hotSongsArr.count;
    }
    if (tableView == self.singerTableView) {
        return self.singerTypeArr.count;
    }
    if (tableView == self.topListTableView) {
        return self.topListArr.count;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.hotSongsTV) {
        HotSongTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"hotsongReuse" forIndexPath:indexPath];
        cell.hotSong = [self.hotSongsArr objectAtIndex:indexPath.row];
        return cell;
    }
    
    if (tableView == self.singerTableView) {
        SingerTypeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"singerTypeReuse" forIndexPath:indexPath];
        cell.singerType = [self.singerTypeArr objectAtIndex:indexPath.row];
        cell.address = [self.addressArr objectAtIndex:indexPath.row];
        return cell;
    }
    if (tableView == self.topListTableView) {
        TopListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"topListTableViewCellReuse" forIndexPath:indexPath];
        cell.topList = [self.topListArr objectAtIndex:indexPath.row];
        return cell;
    }
    
    
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (tableView == self.singerTableView) {
        TypeSingerViewController *typeSingerVC = [[TypeSingerViewController alloc] init];
        typeSingerVC.address = [self.addressArr objectAtIndex:indexPath.row];
        typeSingerVC.area = [self.areaArr objectAtIndex:indexPath.row];
        typeSingerVC.sex = [self.sexArr objectAtIndex:indexPath.row];
        typeSingerVC.type = [self.singerTypeArr objectAtIndex:indexPath.row];
        [self.navigationController pushViewController:typeSingerVC animated:YES];
        [typeSingerVC release];
    }
    if (tableView == self.topListTableView) {
        TopListViewController *topListVC = [[TopListViewController alloc] init];
        TopList *topList = [self.topListArr objectAtIndex:indexPath.row];
        topListVC.type = [topList.type stringValue];
        [self.navigationController pushViewController:topListVC animated:YES];
        [topListVC release];
    }
    
    if (tableView == self.hotSongsTV) {
        MusicPlayViewController *musicPlayVC = [MusicPlayViewController shareInstance];
        HotSong *song = [self.hotSongsArr objectAtIndex:indexPath.row];
        musicPlayVC.address = [NSString stringWithFormat:@"http://tingapi.ting.baidu.com/v1/restserver/ting?from=webapp_music&method=baidu.ting.song.play&format=json&callback=&songid=%@&_=1413017198449", song.song_id];
        musicPlayVC.playingNumber = indexPath.row;
        musicPlayVC.type = @"music";
        musicPlayVC.playSongArr = [NSMutableArray array];
        for (HotSong *song in self.hotSongsArr) {
            NSString *songID = song.song_id;
            [musicPlayVC.playSongArr addObject:songID];
        }
        musicPlayVC.singerName = song.author;
        musicPlayVC.songTitle = song.title;
        musicPlayVC.songID = song.song_id;
    }
    
    
}


- (void)topButtonAction:(UIButton *)button
{
    if ([button.titleLabel.text isEqualToString:@"推荐"]) {
        self.bgScrollView.contentOffset = CGPointMake(0, 0);
    }
    if ([button.titleLabel.text isEqualToString:@"歌手"]) {
        self.bgScrollView.contentOffset = CGPointMake(VIEW_WIDTH, 0);
    }
    if ([button.titleLabel.text isEqualToString:@"排行榜"]) {
        self.bgScrollView.contentOffset = CGPointMake(VIEW_WIDTH * 2, 0);
    }
    if([button.titleLabel.text isEqualToString:@"歌单"]) {
        self.bgScrollView.contentOffset = CGPointMake(VIEW_WIDTH * 3, 0);
    }
    self.changeView.frame = CGRectMake(self.bgScrollView.contentOffset.x / VIEW_WIDTH * VIEW_WIDTH / 4, 94, VIEW_WIDTH / 4, 6);
}

/************************ 上面勿动 ************************/
- (void)localMusicButtonAction:(UIButton *)button
{
    [self.tabBarController setSelectedIndex:0];
}
- (void)FMButtonAction:(UIButton *)button
{
    [self.tabBarController setSelectedIndex:2];
}
- (void)searchButtonAction:(UIButton *)button
{
    Flag *flag = [Flag shareInstance];
    flag.flag = 1;
    [self.tabBarController setSelectedIndex:3];
}
- (void)settingButtonAction:(UIButton *)button
{
    [self.tabBarController setSelectedIndex:4];
}
/************************ 上面勿动 ************************/


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated
{
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    UIButton *button = (UIButton *)[window viewWithTag:1000];
    button.hidden = NO;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
